package com.hz.framework.MyBean;

import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.hz.framework.ajax.BPComDwr;
import com.hz.framework.util.CommonFunc;

//import com.hz.forexception.all.Forlog;

/**
 * 公共查询后分页方法
 * */
public class NewPage extends TagSupport {
	
	
    String nextPage = CommonFunc.PROJECT + "/parts/images/next.gif";//定义下一页图片按钮

    String previousPage = CommonFunc.PROJECT + "/parts/images/previous.gif";//定义上一页图片按钮
    
    String first = CommonFunc.PROJECT + "/parts/images/first.gif";//定义上一页图片按钮
    String end = CommonFunc.PROJECT + "/parts/images/end.gif";//定义上一页图片按钮
	String turn = CommonFunc.PROJECT + "/parts/images/go.gif";//定义转图片按钮
    public void setNextPage(String nextPage) {
        this.nextPage = nextPage;
    }

    public void setPreviousPage(String previousPage) {
        this.previousPage = previousPage;
    }

    public void setEnd(String end) {
		this.end = end;
	}

	public void setFirst(String first) {
		this.first = first;
	}
    
    public int doEndTag() throws JspException {
        try {
            ServletRequest request = pageContext.getRequest();
            pageContext.getOut().println(getPage(request));

        } catch (Exception e) {
        	//Forlog.inslog(this.getClass(), e);
        }
        return super.doEndTag();
    }

    public String getPage(ServletRequest request) {
    	NewPageBean pb = (NewPageBean) request.getAttribute("pagenew");

        StringBuffer page = new StringBuffer();
        page.append("<TABLE width=\"100%\" style='font-size:12px'>");
        page.append("<TR>");
        page.append("<TD width=\"3%\">&nbsp;</TD>");
        page.append("<TD width=\"\" align=\"left\" valign=\"middle\">共<FONT color=\"#849ED6\"><B>");
        page.append(pb.getTotalRows());
        page.append("</B></FONT>条数据，共<FONT color=\"#849ED6\"><B>");
        page.append(pb.getTotalPages());
        page.append("</B></FONT>页。当前是第<FONT color=\"#849ED6\">");
        page.append("<SELECT style=\"width:50px;\" name=\"page\" onChange=\"doindex()\">");
        if ("0".equals(pb.getTotalPages())) {

            page.append("<option vaue=\"0\">0</option>");
        }

        for (int i = 1; i < Integer.valueOf(pb.getTotalPages()) + 1; i++) {

            if (i == Integer.valueOf(pb.getCurrentPage())) {
                page.append("<OPTION value=\" ");
                page.append(i);
                page.append("\" selected >");
                page.append(i);
                page.append("</OPTION>");
            } else {
                page.append("<OPTION value=\" ");
                page.append(i);
                page.append("\" >");
                page.append(i);
                page.append("</OPTION>");
            }
        }
        page.append("</SELECT> </FONT>页。&nbsp;&nbsp;</TD>");
        if(pb.hasPreviousPage != true){
        	page.append("<TD align=\"right\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>");
        }
        if (pb.hasPreviousPage == true) {
            page.append("<TD align=\"left\"><IMG name=\"first\" title=\"首页\" src='"+first+"' onClick=\"dostartend(this)\" style=\"cursor:hand;\"> <IMG name=\"PgUp\" title=\"上一页\"");
	        page.append("src=\"");
	        page.append(previousPage);
            page.append("\" style=\"cursor:hand;\"");
            page.append("onClick=\"previousPage()\"></TD>");
        }
        if (pb.hasNextPage == true) {
            page.append("<TD align=\"left\"><IMG name=\"PgUp\" title=\"下一页\"");
            page.append("src=\"");
            page.append(nextPage);
            page.append("\" style=\"cursor:hand;\"");
            page.append("onClick=\"nextPage()\"> <IMG name=\"offal\" title=\"尾页\" src='"+end+"' onClick=\"dostartend(this)\" style=\"cursor:hand;\"></TD>");
        }

        page.append("<TD align=\"left\">&nbsp;<input name='npage' type='hidden' /><input type='hidden' name='leafNumber'/></TD>");
        page.append("<TD width=\"35%\">&nbsp;<input type=\"hidden\" name=\"thisUrl\" id=\"thisUrl\" value=\""+request.getAttribute("thisUrl")+"\">" +
        		"<input type=\"hidden\" name=\"sqlprint\"  value=\""+BPComDwr.doEncString(pb.SearcHql)+"\">" +
        		"<input type=\"hidden\" name=\"order\"  value=\""+request.getAttribute("order")+"\">" +
        		"<input type=\"hidden\" name=\"taxis\"  value=\""+request.getAttribute("taxis")+"\"></TD>");

        page.append("</TR>");
        page.append("</TABLE>");        

        return page.toString();
    }
}
